home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_37 / ibmmidi.txt < prev   
Text File  |  1995-01-01  |  12KB  |  227 lines

  1.                        IBM MIDI INTERFACE
  2.                           Version 1.0
  3.                         Harley A. Burton
  4.  
  5.                          Copyright 1987
  6.                           Burtech Ind.
  7.  
  8. GENERAL
  9.  
  10. The  Musical  Instrument Digital Interface (MIDI) worked out  by 
  11. Casio, Roland, and others a few years ago has be come the widely 
  12. accepted  standard  of  the  musical  industry  for  interfacing 
  13. everything from keyboard synthesizers, tape recorders, mixers to 
  14. drum  machines and everything else conceivable.   The impact  of 
  15. this  technology  on  the  music  industry  has  been  dramatic.  
  16. Although  hardware and software exists for this  technology,  in 
  17. general it has been quite expensive.   As an example, the Roland 
  18. MPU401  interface,  the most powerful interface for  the  IBM-PC 
  19. family of computers is about $600 list price.   While there have 
  20. been  others developed for a lower cost,  for example the  board 
  21. listed  in  the  June  1986 BYTE  magazine  article,  these  are 
  22. somewhat  complex.   I hope to offer  the  hobbiest/experimenter 
  23. with  a lower cost alternative,  and yet a challenge to  develop 
  24. some or all of the software as a project.
  25.  
  26. Without going deeply into the technical side of MIDI,  it  seems 
  27. to  at  first  scare the world.   It runs at a high  data  rate, 
  28. 32.1250Kbps,  use the odd interface of approximately 5ma current 
  29. loop  and  be optically coupled.   This  sounds  like  something 
  30. totally out of the realm of the home hobbiest.   Not at all,  in 
  31. fact, it is not only possible, it is quite easy.
  32.  
  33. Originally, IBM made the Asynchronous Communications Adapter for 
  34. our IBM-PC's and they didn't know anything about MIDI.  They did 
  35. however  give us the tools we need that can be used to interface 
  36. to MIDI systems with minimum hardware modification and  software 
  37. generation.
  38.  
  39. From here on, I will be discussing modifying an IBM Asynchronous 
  40. Communications Adapter to work with MIDI systems.   While I have 
  41. no  experience with clone serial communications boards,  I  will 
  42. assume that they could be modified similarly and will attempt to 
  43. do  it sometime.   
  44.  
  45. This  discussion  will be quite technical,  but not  beyond  the 
  46. average experimenter.   I hope you will try the ideas  presented 
  47. here  and  pass your findings along to all of us on the  various 
  48. BBS's.
  49.  
  50. DATA RATE GENERATION
  51.  
  52. The original IBM Asynchronous Communications Adapter was capable 
  53. of serial data rates from about 45 baud to 19200 bits per second 
  54. in 5,6,7 and 8 data bits with 1,  1.5 and 2 stop bits, even, odd 
  55. or no parity.   In MIDI,  we would like to run at 31250 bits per 
  56. second,  8 data bits,  no parity and one stop bit.   Well,  just 
  57. change    the   initialization   number,    we   would    think.  
  58. Unfortunately,  the  comm port can't be programmed as it  stands 
  59. for  that baud rate which brings us to the  first  modification.  
  60. The  baud  rate  timing  in  the comm port  is  generated  by  a 
  61. 18.432MHz oscillator labeled in my schematic as U10.   This  is 
  62. then  divided by 10 in U6 to get 1.8432MHz,  the standard  baud 
  63. rate generator.   The 8250 UART U11 which actually does all  the 
  64. work  has an on-chip oscillator which could be used to  generate 
  65. the desired frequency.  
  66.  
  67. As it turns out,  by removing U6,  the 7490 used to divide by 10 
  68. and  connecting  a 3MHz crystal between pins 16 and 17 of  U11, 
  69. the  8250,  the  comm port will now operate at  31250  bits  per 
  70. second, the MIDI standard.
  71.  
  72. The comm port will no longer operate as a standard serial board, 
  73. but who cares.  These things are cheap enough to convert to MIDI 
  74. permanently.
  75.  
  76. On the Serial/Printer Adapter which is the type used in the IBM-
  77. PC/AT,   the   generation  is  slightly  different.    The  base 
  78. oscillator is 1.8432MHz as it comes from the factory.   This is 
  79. buffered in U11,  a 74LS05.   The final serial port device is  a 
  80. NS16450,  an  upgraded 8250.   This board requires breaking the 
  81. foil trace between pin 2 on U11 and pin 16 on U5,  the NS16450.  
  82. This can be simply a cut with an X-Acto knife.   Then connect  a 
  83. 3MHz crystal between pins 16 and 17 as in the other board.  
  84.  
  85. The  maximum operating frequency of both boards is 3.1MHz,  but 
  86. there  is adequate "head room" for this to work  satisfactorily.  
  87. It also turns out that by using the 3Mhz crystal,  the internal 
  88. divisor ratio is such that when you tell the port to  initialize 
  89. for 19200bps,  it will actually configure itself for 31250bps.  
  90. The ratio of 3.0Mhz to 1.8432MHz equals the ratio of 31250bps 
  91. to   19200bps  (3/1.8432  =  31250/19200).    This  will   have 
  92. implications which will be described later in the software.
  93.  
  94. 5 Ma CURRENT LOOP
  95.  
  96. The   original  IBM  Asynchronous  Communications  Adapter   had 
  97. provisions  for the archaic 20 ma current loop  standard.   This 
  98. has  disappeared  on the Serial/Printer Adapter and  most  clone 
  99. adapters.   For our purposes,  this is a shame.  I will describe 
  100. first  converting the IBM Asynchronous Communications Adapter to 
  101. 5ma  current  loop  then provide some  thoughts  on  the  other 
  102. adapters.
  103.  
  104. On  the  IBM  Asynchronous  Communications  Adapter,  the  20ma 
  105. current  loop was configured by turning jumper block XU5  around 
  106. opposite   of  that  required  by  RS-232  (yes,   I  am   being 
  107. intentionally vague, because I can't remember off hand which way 
  108. that  is).   The 20ma current loop is provided by 3 sections of 
  109. U8  paralleled  and  driving the 20ma loop through  a  100  ohm 
  110. resistor,  R3.  By changing this resistor to a 390 ohm resistor, 
  111. the  current should be a little hot 5ma.   A 470  ohm  resistor 
  112. could  be used if you are not driving long 5ma  lines.   Either 
  113. will be within safety range of the MIDI requirements.   A 220 in 
  114. series  with a 180 ohm,  would of course be exact.   Any of  the 
  115. above will work fine.
  116.  
  117. On the recieve side, the IBM Asynchronous Communications Adapter 
  118. already  has  an opto-coupler interface provided  by  U4.   This 
  119. should be useable without modification.
  120.  
  121. An adapter will be needed to go from the 25 Pin "D" connector on 
  122. the  back  of the Asynchronous Communications Adapter to a  MIDI 
  123. 5pin  DIN connector used for MIDI.   The parts for this can  be 
  124. purchased  from  Radio Shack and since I  don't  have  schematic 
  125. capability with this word processor, I won't go into it here.
  126.  
  127. For  a board other than the Asynchronous Communications  Adapter 
  128. such as a clone or the IBM Serial/Printer Adapter,  an RS-232 to 
  129. 5ma  adapter will need to be built.   I won't design one  here, 
  130. it's  really pretty trivial,  but I would suggest receiving  the 
  131. RS-232  with a MC1489 then driving the 5ma with 3 sections of a 
  132. 74LS04  tied  in parallel then driving MIDI through  a  390  ohm 
  133. resistor.   The  receive side could use any of the  optocouplers 
  134. that are usually specified for MIDI, such as the one in the BYTE 
  135. article mentioned above.   This could then drive a MC1488 RS-232 
  136. line  driver.   A  small  5volt power supply will  have  to  be 
  137. provided in this interface.
  138.  
  139. I  might  suggest that if you have to build the RS-232  to  5ma 
  140. converter,  use  some  of the extra sections of the  devices  to 
  141. build some MIDI through buffers, splitters, etc.
  142.  
  143. MIDI SOFTWARE
  144.  
  145. Without  going  into  the software in great  detail,  there  are 
  146. several  built-ins and hints that I can give which may  help  in 
  147. writing  your own software package.   All of the software  ideas 
  148. are  in  IBM BASIC for clarity.   These built-ins  are  probably 
  149. available in other languages as well.
  150.  
  151. The  first thing we will need is beat timing or tempo.   I  have 
  152. chosen the easy way out again.  I built a tempo generator with a 
  153. type 555 timer and a few components that generates a pulse at 24 
  154. times  the quarter note beat.   This allows me to generate  32nd 
  155. notes  and 16th triplets,  not that I would ever play that fast.  
  156. I  built  it  with  a range of 20 to 240  beats  per  minute  (8 
  157. pulses/second  to 96 pulses/second).   This I connected  to  the 
  158. trigger input of a game port.   Again, I had one and didn't feel 
  159. like  building a trigger timer board.   This I control manually, 
  160. but  you could use the internal timer section 2 of the  8253  on 
  161. your IBM-PC mother board.  I don't know how to do this and would 
  162. appreciate if anyone knows how, please tell me.
  163.  
  164. I  use  the  "ON  TRIG(1)"  statement in  BASIC  to  jump  to  a 
  165. subroutine in which I keep track of which portion of a beat I am 
  166. in.   This  provides  the  basic timing for  both  transmit  and 
  167. receive.   I  will come back to this later.  I wish that IBM had 
  168. given  us better resolution on the ON TIMER function,  it  could 
  169. have  been  used  as  a beat counter  but  with  only  1  second 
  170. resolution there isn't much you can do with it unless your music 
  171. is VERY VERY slow.
  172.  
  173. The  initialization  of  the  serial port  is  quite  simple  to 
  174. implement  for  MIDI.   I use the "OPEN  COM1:19200,N,8,1,CS,DS" 
  175. statement  to  initialize the port.   Remember that  because  we 
  176. changed  the crystal to 3MHz,  opening at 19200 in software  is 
  177. actually  opening at 31250 bps.   This works!!!   I  don't  like 
  178. error  checking  in  hardware,  so  I disable the  CTS  and  DTS 
  179. signals.  
  180.  
  181. I  have notes to be transmitted assigned to portions of a  beat.  
  182. These  are  built off-line by a conversion  routine  that  takes 
  183. information  from  the music processor SongWright and  builds  a 
  184. file  of notes and timing to be transmitted over MIDI.   I won't 
  185. go into how this works until I get it totally ready, but what it 
  186. does is this:
  187.  
  188.      When a TRIG(1) interrupt occurs,  the software checks if  a      
  189.      note  or group of notes are to be sent.   If they  are,  it 
  190.      builds the group of notes with statements like
  191.  
  192.           J$ = CHR$(14)+CHR$(23)+CHR$(77)...
  193.  
  194.      Then transmits the string with a 
  195.  
  196.           PRINT#1,J$
  197.  
  198.      Since the output is a buffered,  interrupt driven transmit, 
  199.      the  notes are transmitted at 31250 bps.  with  no  further 
  200.      assistance  from the user.   Unless there is a LOT of notes 
  201.      to  be sent,  as in 16 voice chords,  along with  big  drum 
  202.      sounds, they should sound correct.  This is a limitation of 
  203.      the  transmission  media,  MIDI,  however and not  the  IBM 
  204.      hardware.
  205.  
  206. I also use the "ON COM(1)" statement to set up a receive routine 
  207. for  MIDI.   This allows me to avoid polling the receive side so 
  208. that I can do other things.  When a note is received via MIDI, I 
  209. jump to a routine that gets the note,  then reads the portion of 
  210. beat counters to see what beat time I should assign to  it.   It 
  211. checks for several other things, like note off, system messages, 
  212. etc.   These  are  interpreted and used  where  appropriate.   I 
  213. assume  that  I can receive anything anytime and I have to  know 
  214. what  I  received  and  what to do with it so  this  routine  is 
  215. potentially a little longer than necessary.
  216.  
  217. CONCLUSION
  218.  
  219. I  have attempted to describe a hardware and software experiment 
  220. into  the fascinating world of MIDI.   I hope to  continue  with 
  221. this experiment and eventually build a full MIDI system with all 
  222. of  the  features we have dreamed about.   I would like  to  get 
  223. input from all you and hope you will help me in this experiment.  
  224. If you develop any software in this line,  please make it public 
  225. domain so that we all can enjoy it.  
  226.  
  227.